//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __ELASTOS_KSTAT_H__
#define __ELASTOS_KSTAT_H__

#ifdef KCONFIG_MSTAT

typedef struct {
    //cache mem
    UInt32 uAllocedBytesOfCache;
    UInt32 uTotalPagesOfCache;
    //buddysys
    UInt32 uAllocedKernelPages;
    UInt32 uAllocedPhysicsPages;
    //total pages
    UInt32 uTotalPages;
    //free pages
    UInt32 uFreePages;

} StatInfo, *PStatInfo;

EXTERN Void StatInit();

EXTERN Void GetStatInfo(StatInfo *pStatInfo);

EXTERN Void StatTotalPagesOfCache();

EXTERN Void StatKMalloc(UInt32 uBytes);
EXTERN Void StatKFree(UInt32 uBytes);

EXTERN Void StatAllocKernelPages(UInt32 uOrder);
EXTERN Void StatFreeKernelPages(UInt32 uOrder);

EXTERN Void StatAllocPages(UInt32 uOrder);
EXTERN Void StatFreePages(UInt32 uOrder);

#ifndef STAT_INIT
#define STAT_INIT \
        do { \
            StatInit(); \
        } while(0);
#endif //STAT_INIT

#ifndef STAT_TOTAL_PAGES_OF_CACHE
#define STAT_TOTAL_PAGES_OF_CACHE \
        do { \
            StatTotalPagesOfCache(); \
        } while(0);
#endif //STAT_TOTAL_PAGES_OF_CACHE

#ifndef STAT_KMALLOC
#define STAT_KMALLOC \
        do { \
            StatKMalloc(INDEX_TO_SIZE(uIndex)); \
        } while(0);
#endif //STAT_KMALLOC

#ifndef STAT_KFREE
#define STAT_KFREE \
        do { \
            StatKFree(INDEX_TO_SIZE(pFreeList - (uint_t*)s_aFreeLists)); \
        } while(0);
#endif //STAT_KFREE

#ifndef STAT_ALLOC_KERNEL_PAGES
#define STAT_ALLOC_KERNEL_PAGES \
        do { \
            StatAllocKernelPages(uOrder); \
        } while(0);
#endif //STAT_ALLOC_KERNEL_PAGES

#ifndef STAT_FREE_KERNEL_PAGES
#define STAT_FREE_KERNEL_PAGES \
        do { \
            StatFreeKernelPages(uOrder); \
        } while(0);
#endif //STAT_FREE_KERNEL_PAGES

#ifndef STAT_ALLOC_PAGES
#define STAT_ALLOC_PAGES \
        do { \
            StatAllocPages(uOrder); \
        } while(0);
#endif //STAT_ALLOC_PAGES

#ifndef STAT_FREE_PAGES
#define STAT_FREE_PAGES \
        do { \
            StatFreePages(uOrder); \
        } while(0);
#endif //STAT_FREE_PAGES

#else

#define STAT_INIT

#define STAT_TOTAL_PAGES_OF_CACHE

#define STAT_KMALLOC
#define STAT_KFREE

#define STAT_ALLOC_KERNEL_PAGES
#define STAT_FREE_KERNEL_PAGES

#define STAT_ALLOC_PAGES
#define STAT_FREE_PAGES

#endif //KCONFIG_MSTAT

#endif //__ELASTOS_KSTAT_H__
